package com.wgq.uitest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.wgq.uitest.R;
import com.wgq.uitest.exp3.MyClickListenerTest;
import com.wgq.uitest.exp3.MyProgressDialog;
import com.wgq.uitest.exp3.SystemInfo;

public class Main2Activity extends AppCompatActivity implements View.OnClickListener {

    TextView text1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        text1 = (TextView) findViewById(R.id.text1);

        Button btn1 = (Button) findViewById(R.id.btn1);
        Button btn2 = (Button) findViewById(R.id.btn2);
        Button btn3 = (Button) findViewById(R.id.btn3);
        Button btn4 = (Button) findViewById(R.id.btn4);
        Button btn5 = (Button) findViewById(R.id.btn5);

        Button btn7 = (Button) findViewById(R.id.btn7);
        Button btn8 = (Button) findViewById(R.id.btn8);
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(new MyClickListener());
        btn3.setOnClickListener(
            new MyClickListener(){
                public void onClick(View v) {
                    text1.setText("btn3按钮被点击了！");
                }
        });
        //lambda表达式
        btn4.setOnClickListener(view -> text1.setText("btn4按钮被点击了！"));
        //外部类
        btn5.setOnClickListener(new MyClickListenerTest(text1));

        btn7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Main2Activity.this, SystemInfo.class);
                startActivity(intent);
            }
        });

        btn8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Main2Activity.this, MyProgressDialog.class);
                startActivity(intent);
            }
        });
    }

    /**
     * 自身作为监听器
     * @param v
     */
    @Override
    public void onClick(View v) {
        text1.setText("btn1按钮被点击了！");
    }

    /**
     * 内部类作为监听器
     */
    class MyClickListener implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            text1.setText("btn2按钮被点击了！");
        }
    }

    /**
     * 直接绑定到标签
     * @param v
     */
    public void ClickHandler(View v){
        text1.setText("btn6按钮被点击了！");
    }
}
